home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / Watcher / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-02  |  2.3 KB  |  87 lines

  1. /*
  2.    main: main routine for the watcher program.
  3.  
  4.    read from a file describing commands (pipelines) to execute, formats of
  5.        the output, max changes allowed (% or absolute), and max & min
  6.        values for various fields.
  7.    problems noticed are reported.
  8.    as a side effect, be able to pretty print the description file
  9.        (originally used to verify parsing).
  10.  
  11.    outline of program:
  12.     parse control file and build data structures.
  13.     run each pipeline and compare output to previous output (only
  14.         save relevant fields; save directory is either default
  15.         or command line specified; no previous file or format
  16.         changed (ie we are watching different or new fields) we
  17.         create new file and next time we do compare).
  18.         differences that are not allowable are reported.
  19.     
  20.    Usage of program:
  21.     watcher [-p] [-v] [-h histfile] [-f controlfile] [-n]
  22.  
  23.     -p : pretty print control file as a verification of parse
  24.         (default no pretty print).  This option prevents
  25.         processing of control file.
  26.     -v : be verbose when doing work; useful for debugging.
  27.         Shows what was read from processes, or if used in
  28.         conjunction with -p shows what the lexical analyzer
  29.         returned.
  30.     -h : file in which to save output for future compare (default
  31.         ./watcher.history).
  32.     -f : controlfile to use (default ./watcherfile or ./Watcherfile).
  33.     -n : turn off 'history' stuff, if set.
  34.  
  35.    Note that the basic data structures are all linear linked lists, with
  36.    many items in the list being heads of other lists.  When problems
  37.    occur, get out the pencil and paper and start drawing the lists.  
  38.  
  39.    Kenneth Ingham
  40.  
  41.    Copyright (C) 1987 The University of New Mexico
  42. */
  43.  
  44. #include "defs.h"
  45.  
  46. main(argc, argv)
  47. int argc;
  48. char *argv[];
  49. {
  50.     extern int parse_error;
  51.     extern struct cmd_st *clist;
  52.     extern int pflag, nflag;
  53.     extern char *myname, *histfilename;
  54.     extern int errno;
  55.     extern char *sys_errlist[];
  56.     FILE *hf;
  57.  
  58.     do_args(argc, argv);
  59.     init_sigs();
  60.     open_cf();
  61.  
  62.     if (yyparse() == 1 || parse_error) {
  63.         fprintf(stderr, "%s: parse error in control file.\n", myname);
  64.         exit(1);
  65.     }
  66.  
  67.     if (clist == NULL) {
  68.         fprintf(stderr, "No command list to execute!\n");
  69.         exit(1);
  70.     }
  71.  
  72.     if (pflag)
  73.         pp(clist);
  74.     else {
  75.         if (! nflag) {
  76.             read_hist();
  77.             hf = fopen(histfilename, "w");
  78.             if (hf == NULL) {
  79.                 fprintf(stderr, "Unable to open '%s': %s\n",
  80.                     histfilename, sys_errlist[errno]);
  81.                 exit(1);
  82.             }
  83.         }
  84.         doit(hf);
  85.     }
  86. }
  87.